package com.example.produce.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.amqp.core.Queue;

@Configuration
public class RabbitCofnig {
    @Bean(name = "helloQueue")
    public Queue CreateQueue() {
        return new Queue("hello"); //实例化队列hello 消费者1监听
    }
    @Bean(name = "infoQueue")
    public Queue CreateQueue2(){
        return new Queue("info"); //创建队列info 由消费者2监听
    }
    @Bean
    public FanoutExchange createFunOutChange(){
        return  new FanoutExchange("Exchange"); //配置交换机
    }

    @Bean
    public Binding bingExchange(@Qualifier("helloQueue") Queue queue, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queue).to(fanoutExchange); //将交换机与相关队列绑定
    }

    @Bean
    public Binding bingExchange2(@Qualifier("infoQueue") Queue queue,FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }


}
